'use strict'
const path = require('path')
const settings = require('./src/config')
// const CompressionWebpackPlugin = require('compression-webpack-plugin')

function resolve(dir) {
  return path.join(__dirname, dir)
}

module.exports = {
  outputDir: 'dist/build/h5',
  transpileDependencies: ['el-admin-layout'],
  configureWebpack: {
    name: settings.title,
    resolve: {
      alias: {
        '@': resolve('src'),
        '@ele': resolve('element-ui-personal')
      }
    }
  },
  devServer: {
    disableHostCheck: true
  },
  chainWebpack(config) {
    config.plugins.delete('preload')
    config.plugins.delete('prefetch')

    // set svg-sprite-loader
    config.module.rule('svg').exclude.add(resolve('src/assets/icon')).end()
    config.module
      .rule('icons')
      .test(/\.svg$/)
      .include.add(resolve('src/assets/icon'))
      .end()
      .use('svg-sprite-loader')
      .loader('svg-sprite-loader')
      .options({ symbolId: 'icon-[name]' })
      .end()

    //   config.when(!settings.isDev, (config) => {
    //     //将css合并到一个文件中
    //     //https://github.com/vuejs/vue-cli/issues/2843
    //     config.optimization
    //       .removeEmptyChunks(true)
    //       .splitChunks({
    //         cacheGroups: {
    //           style: {
    //             name: 'style',
    //             type: 'css/mini-extract',
    //             chunks: 'all'
    //           }
    //         }
    //       })
    //       .end()

    //     //生成gz
    //     config
    //       .plugin('compression-webpack-plugin')
    //       .use(CompressionWebpackPlugin, [
    //         {
    //           test: new RegExp('\\.(js|css)$'), //匹配文件名
    //           threshold: 10 * 1024 //对10K以上的数据进行压缩
    //         }
    //       ])
    //       .end()
    //   })
  }
}
